layui.use(["element", 'layer', 'form', 'table'], function () {
  var element = layui.element,
    form = layui.form,
    layer = layui.layer,
    table = layui.table;
  setTable(vm.tableIns);
  // 重新渲染表格
  function setTable(data) {
    table.render({
      elem: '#table1',
      data: data,
      cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
      cols: [
        [ //标题栏
          {
            field: 'id',
            title: 'ID',
            width:50
          }, {
            field: 'name',
            title: '理财产品名称',
            minWidth:280
          }, {
            field: 'totalP',
            title: '募集资金总额(万元)'
          }, {
            field: 'pzPr',
            title: '已配置资产金额(万元)'
          }, {
            field: 'num',
            title: '配置资产个数'    
          }, {
            field: 'upTime',
            title: '更新时间',
            width:110
          }, {
            fixed: 'right',
            title: '操作',
            toolbar: '#barDemo',
            width:90
          }
        ]
      ]
    });
  }
  $('#searchBtn').on('click', function () {
    var name = vm.name,Arr = [];
    if(name){
      Arr = vm.defaultData.filter(function (item) {
        return item.name == name
      });
    }else{
      Arr = vm.defaultData;
    }
    setTable(Arr);
  });
  //监听行工具事件
  table.on('tool(demo)', function (obj) {
    var data = obj.data;
    if (obj.event === 'detail') {
      var id = data.id;
      window.location.href = 'CCXQ_'+id+'.html';
    }
  });

});
// AssetCode  资产代码  

var vm = new Vue({
  el: '#app',
  data: {
    name: '建行“乾元-众享”理财产品2018第3期',
    ArrData: [],
    totalVisible: false,
    tableIns: [],
    defaultData: []
  },
  mounted: function () {
    this.init()
  },
  methods: {
    init: function () {
      localStorage.setItem('navigation','<a href="#">首页</a><span lay-separator="">/</span><a href="">大类资产配置模型</a><span lay-separator="">/</span><a><cite>产品资产持仓查询</cite></a>');
      this.defaultData = this.tableIns;
      var arry =["1;建行“乾元-众享”理财产品2018第1期;500,000;500,000;5;2018-10-13","2;建行“乾元-众享”理财产品2018第2期;700,000;700,000;5;2018-11-13","3;建行“乾元-众享”理财产品2018第3期;1,000,000;850,000;5;2018-12-15"] ;
      var keys = ['id', 'name', 'totalP', 'pzPr', 'num', 'upTime'];
      arry.map(item => {
        var keyData = item.split(";");
        var obj = {};
        keyData.map((item, index) => {
          obj[keys[index]] = item;
        });
        this.ArrData.push(obj);
      });
      this.tableIns = this.defaultData = this.ArrData;
    }
  }
})